package com.dhf.framework.system.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.dhf.framework.common.BaseController;
import com.dhf.framework.system.entity.SysMenu;
import com.dhf.framework.system.entity.SysUser;
import com.dhf.framework.system.service.SysMenuService;

/**
 * 首页
 * @author dahaofeng
 *
 */
@Controller
public class IndexController extends BaseController {

	@Resource(name="sysMenuService")
	private SysMenuService sysMenuService;
	
//	@Autowired
//	private JdbcTemplate jdbcTemplate;
	
    /**
     * 
     * 功能描述：首页
     * 输入参数：<按照参数定义顺序> 
     * @param 参数说明
     * 返回值:  类型 <说明> 
     * @return 返回值
     * @see 需要参见的其它内容
     */
    @RequestMapping("/")
    public ModelAndView welcome(){
    	SysUser user=getUser();
        ModelAndView model = new ModelAndView();
        List<SysMenu> allmenuList =sysMenuService.listAllByUserId(user.getId());
        for(SysMenu sysMenu : allmenuList){
            List<SysMenu> subList = sysMenuService.listSubMenuByParentId(sysMenu.getMenuId().toString());
            if(subList != null && !subList.isEmpty()){
                sysMenu.setSubMenu(subList);
                sysMenu.setHasMenu(true);
            }else{
                sysMenu.setHasMenu(false);
            }
        }
        model.setViewName("index");
        model.addObject("menuList", allmenuList);
        model.addObject("userName", user.getName());
        return model;
    }
    
    
    @RequestMapping("404")
    public ModelAndView NotFindPage(){
        ModelAndView model = new ModelAndView();
        model.setViewName("common/404");
        return model;
    }
    
    @RequestMapping("error")
    public ModelAndView errorPage(){
        ModelAndView model = new ModelAndView();
        model.setViewName("common/error");
        return model;
    }
    
}
